#include "parser.h"
#include <iostream>
#include <fstream>
#include <string>
#include <list>
#include <algorithm>

using namespace std;
parser *p;

void read_line(const string &line)
{
	for(int i = 0; i < line.size(); ++i) {
		char c = line[i];
		parse_add(p, c);
		parse(p);
	}
	char c = '\n';
	parse_add(p, c);
	parse(p);
}

void cb(void *user, char *tag, char **attr)
{
	cout << tag << " ";
	for(int i = 0; attr[i]; ++i) {
		cout << attr[i] << " ";
	}
	cout << endl;
}

int main(int argc, char *argv[])
{
	p = parser_create();
	p->callback = &cb;
	ifstream ifs("parsefile.txt");
	list<string> lines;
	while(ifs.good()) {
		string line;
		getline(ifs, line);
		lines.push_back(line);
	}
	lines.pop_back();
	for_each(lines.begin(), lines.end(), &read_line);
	parser_delete(p);
	return 0;
}
